<?php defined('BASEPATH') OR exit('No direct script access allowed');

class defective extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		
		if (!$this->ion_auth->logged_in())
		{
			//redirect them to the login page
			redirect('auth/login', 'refresh');
		}
		elseif (!$this->ion_auth->is_admin())
		{
			//redirect them to the home page because they must be an administrator to view this	
			redirect('/', 'refresh');
		}
		$this->load->model('defective_model');
        $this->load->library('datatables');			
	}
	
public function view_alldefective()
{
 $meta['page_title'] = 'ALL Defective ';
$this->load->view('common/header',$meta);
 $this->load->view('defective/all_defective');
$this->load->view('common/footer');

}	
public function get_defective()
{
echo $this->defective_model->get_view_defective();

}
	
public function collect_docket($id)
{

$meta['page_title'] = 'Collect Docket ';
$this->data['case']=$this->defective_model->get_case($id)->row();
$this->load->view('common/header',$meta);
 $this->load->view('defective/collect_docket',$this->data);
$this->load->view('common/footer');

}	
	
public function docket_no()
{
$case_id=$_REQUEST['case_id'];
$email=$this->input->post('email');
if(!empty ($email))
{
$email=$_REQUEST['email'];
}
else
{
$email=0;

}
$docket_no=$_REQUEST['docket'];
$data=array('case_id'=>$case_id,
             'docket_no'=>$_REQUEST['docket'],
			 'dispatch_date'=>$_REQUEST['dispatch_date'],
			 'expected_date'=>$_REQUEST['expected_date'],
			 'customer_informed'=>$email,);
		 
$this->defective_model->docket_no($data);
redirect('admin/defective/view_alldefective');	 

}	
public function new_docket()
{
$meta['page_title'] = 'Received Docket ';
$this->load->view('common/header',$meta);
 $this->load->view('defective/redispatch_docket');
$this->load->view('common/footer');
}	
function get_case_no()
	{ 
	$docket=$_REQUEST['id'];
	$data=$this->defective_model->chk_case($docket)->row();
	if($data)
	{
	echo $data->docket_no;
	}
	else
	{
	echo "";
	}
	}	
	
function new_dispatch()
	{
	  
				$sl_no = $this->input->post('sl_no');
				$hp_no=$_REQUEST['case_no'];
			//	$case_id=$this->docket_model->get_case_id($case_no)->row();
			    $docket=$this->input->post('docket_no');
				$received=$this->input->post('received_date');
				$response=$this->input->post('response');
			    $length = count($sl_no);
				
					for($i=0; $i<$length; $i++){
						$case_no=$this->defective_model->get_case_id($hp_no[$i])->row();
						$data['case_no']=$case_no->case_no;
					
						$data['docket_no']=$docket[$i];
				       $data['received_date']=$received[$i];
					   $data['response']=$response[$i];
				      $data['case_id'] =$case_no->id;
			       $this->defective_model->received_docket($data);
					$this->defective_model->update_case_status($id[$i]->id);
						}							
  
                   redirect('admin/defective/all_notassigned');
	}	
	
public function all_redispatch()
{
$meta['page_title'] = 'ALL Received Redispatch ';
$this->load->view('common/header',$meta);
 $this->load->view('defective/all_redispatch');
$this->load->view('common/footer');

}	
	
public function getall_docket()
{
echo $this->defective_model->get_disp_view();

}	
public function all_notassigned()
{
$meta['page_title'] = 'Not Assigned Redispatch ';
$this->load->view('common/header',$meta);
 $this->load->view('defective/not_assigned');
$this->load->view('common/footer');
}	
public function getall_notassigned()
{
echo $this->defective_model->get_notassigned();

}	
public function assigned_engineer($id)
{	
$data['engineer']=$this->defective_model->get_engineer();
$data['order']=$this->defective_model->detail_redispatch($id)->row();
$meta['page_title'] = 'Assigned Engineer ';
$this->load->view('common/header',$meta);
 $this->load->view('defective/assigned_engineer',$data);
$this->load->view('common/footer');		
}	
public function engineer_assign()
{
$insert=array('case_id'=>$_REQUEST['case_id'],
              'status_id'=>5,
               'engineer_id'=>$_REQUEST['id_engineer'],
               'docket_no'=>$_REQUEST['docket_no'],
                'assigned_date'=>$_REQUEST['assigned_date'],
                'expected_date'=>$_REQUEST['expected_date'],);				
$this->defective_model->insert_repair($insert);
$this->defective_model->update_case($_REQUEST['case_id']);
 redirect('admin/defective/all_notassigned');
}




	
	
	
	}?>